<template>
  <!-- 站点详细统计列表 -->
  <div>
    <!-- 表格 -->
    <el-table :data="tableData"
              v-loading="loading"
              border
              show-summary
              stripe
              :default-sort="{prop: 'maintainAbnormityPercentage', order: 'descending'}">
      <el-table-column prop="province"
                       label="省份"
                       sortable
                       width="90"
                       align="center"></el-table-column>
      <el-table-column prop="total"
                       label="测站数"
                       align="center">
        <template slot-scope="props">
          <span v-if="props.row.total>0">{{ props.row.total }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="normal"
                       sortable
                       label="来报(个)"
                       align="center">
        <template slot-scope="props">
          <span v-if="props.row.normal>0">{{ props.row.normal }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="abnormity"
                       label="缺报(个)"
                       sortable
                       align="center">
        <template slot-scope="props">
          <span v-if="props.row.abnormity>0">{{ props.row.abnormity }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="abnormityPercentage"
                       label="缺报率"
                       sortable
                       width="160"
                       align="center">
        <template slot-scope="props">
          <span v-if="props.row.abnormityPercentage === 0">-</span>
          <span v-else
                :class="{'table-background-color-red' : props.row.abnormityPercentage > 50}">{{ props.row.abnormityPercentage + '%'}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="maintainTotal"
                       label="我司维护"
                       sortable
                       align="center">
        <template slot-scope="props">
          <span v-if="props.row.maintainTotal>0">{{ props.row.maintainTotal }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="maintainNormal"
                       label="来报(个)"
                       sortable
                       align="center">
        <template slot-scope="props">
          <span v-if="props.row.maintainNormal>0">{{ props.row.maintainNormal }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="maintainAbnormity"
                       label="缺报(个)"
                       sortable
                       align="center">
        <template slot-scope="props">
          <span v-if="props.row.maintainAbnormity>0">{{ props.row.maintainAbnormity }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="maintainAbnormityPercentage"
                       label="缺报率"
                       sortable
                       width="160"
                       align="center">
        <template slot-scope="props">
          <span v-if="props.row.maintainAbnormityPercentage === 0">-</span>
          <span v-else
                :class="{'table-background-color-red' : props.row.maintainAbnormityPercentage > 50}">{{ props.row.maintainAbnormityPercentage + '%' }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <!-- <el-pagination layout="total, sizes, prev, pager, next, jumper"
                   :total="pagging.total"
                   :page-sizes="pagging.sizes"
                   :current-page="pagging.currentPage"
                   @size-change="sizeChange"
                   @current-change="pageChange">
    </el-pagination> -->
  </div>
</template>
<script>
import { getStatisArea } from '@/api/site'
import _ from 'lodash'
export default {
  props: {
    searchForm: Object
  },
  data() {
    return {
      loading: false,
      exprotLoading: false,
      // 表格数据
      tableData: [],
      // 分页属性
      pagging: {
        total: 0,
        currentPage: 1,
        pageSize: 50,
        sizes: [50, 100, 300, 500, 1000]
      }
    }
  },
  methods: {
    search() {
      this.pagging.currentPage = 1
      this.getTableData()
    },
    getTableData() {
      this.loading = true
      const params = _.assignIn({}, this.searchForm, {
        pageIndex: this.pagging.currentPage,
        pageSize: this.pagging.pageSize
      })
      // 多选条件处理
      params.territory = params.territory.join(',')

      getStatisArea(params).then(res => {
        if (res.data.success) {
          const result = res.data.data
          this.tableData = result
          this.loading = false
        }
      })
    },
    // 每页显示条数变更新
    sizeChange(size) {
      this.pagging.pageSize = size
      this.getTableData()
    },
    // 跳转到页面
    pageChange(curPage) {
      this.pagging.currentPage = curPage
      this.getTableData()
    },
    // 导出
    exprotInfo() { }
  }
}
</script>
